package com.carnation.servlet;

import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

public class RedirectServlet extends HttpServlet{

	private static final long serialVersionUID = 1L;
	private Logger logger = Logger.getLogger(RedirectServlet.class);
	
	protected void doPost(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse){
		doGet(httpServletRequest, httpServletResponse);
	}
	
	protected void doGet(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse){
		String type = httpServletRequest.getParameter("type");
		String url;
		if(type.equals("head")){
			url = "/SecurityJsp/headView.jsp";
		}
		else if(type.equals("group")){
			url = "/SecurityJsp/groupView.jsp";
		}
		else if(type.equals("menu")){
			url = "/SecurityJsp/menuView.jsp";
		}
		else if(type.equals("root")){
			url = "/SecurityJsp/rootView.jsp";
		}
		else{
			url = "/common/404.jsp";
		}
		RequestDispatcher rd = httpServletRequest.getRequestDispatcher(url);
		try{
			rd.forward(httpServletRequest, httpServletResponse);
		}
		catch(Exception e){
			logger.error("转发错误",e);
		}
	}
}
